package com.inspur.sc.springboot.dao;

import com.inspur.sc.springboot.entity.SysRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;


public interface SysRoleDao extends JpaRepository<SysRole, Integer> {

    Page<SysRole> findByNameLike(String name, Pageable pageable);

    @Query(value = "SELECT r.* from sys_role r LEFT JOIN sys_role_user sru ON  r.id=sru.sys_role_id where sru.sys_user_id=?1", nativeQuery = true)
    List<SysRole> findByUserId(Integer userId);

    @Query(value = "SELECT r.* from sys_role r LEFT JOIN sys_group_role gr on r.id=gr.sys_role_id where sys_group_id=?1",nativeQuery = true)
    List<SysRole> findSysRoleByGroupId(Integer groupId);
}
